package oralExamSchedulingSystemTest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;

import junit.framework.*;
import oralExamSchedulingSystem.CSVParser;
import oralExamSchedulingSystem.Scheduler;
import oralExamSchedulingSystem.Student;
import oralExamSchedulingSystem.Timetable;

import org.junit.Test;
import org.junit.After;
import org.junit.Before;

public class TestCSVParser extends TestCase{
	
	private CSVParser csvParser;
	
	public TestCSVParser(String name)
    {
            super(name);
    }

    @Before
    public void setUp() throws Exception 
    {
            
    }

    @After
    public void tearDown() throws Exception 
    {
    }
    
    @Test
    public void testRead5records() throws IOException{
    	csvParser = new CSVParser();
    	ArrayList <Student> actualArrayList = csvParser.inputParseCsv(".\\input\\test1.csv");
    	ArrayList <Student> expectedArrayList= new ArrayList <Student>();
    	//int sid,String className,int classNumber,String name,char sex
    	/*06043, 5D, 21, AAA, F
    	  06157, 5E, 3, BBB, M
    	  06182, 5A, 30, CCC, F
    	  07132, 5B, 11, DDD, M
    	  08003, 5C, 20, EEE, F*/
    	expectedArrayList.add(new Student(Integer.parseInt("06043"), "5D", Integer.parseInt("21"), "AAA", 'F'));
    	expectedArrayList.add(new Student(Integer.parseInt("06157"), "5E", Integer.parseInt("3"), "BBB", 'M'));
    	expectedArrayList.add(new Student(Integer.parseInt("06182"), "5A", Integer.parseInt("30"), "CCC", 'F'));
    	expectedArrayList.add(new Student(Integer.parseInt("07132"), "5B", Integer.parseInt("11"), "DDD", 'M'));
    	expectedArrayList.add(new Student(Integer.parseInt("08003"), "5C", Integer.parseInt("20"), "EEE", 'F'));
    	
    	assertEquals(expectedArrayList.equals(actualArrayList), true);
    }
    
    @Test
    public void testOutput5records()throws IOException{
    	csvParser = new CSVParser();
    	ArrayList <Student> studentList = csvParser.inputParseCsv(".\\input\\test1.csv");
    	String expectedOuputString="[[Group0{501 9:00 [5A:30:CCC, 5B:11:DDD, 5C:20:EEE, 5D:21:AAA]}, Group1{502 9:00 []}, Group2{503 9:00 []}, Group3{504 9:00 []}, Group4{505 9:00 []}, Group5{506 9:00 []}, Group6{507 9:00 []}], [Group7{501 9:15 []}, Group8{502 9:15 []}, Group9{503 9:15 []}, Group10{504 9:15 []}, Group11{505 9:15 []}, Group12{506 9:15 []}, Group13{507 9:15 []}], [Group14{501 9:30 []}, Group15{502 9:30 []}, Group16{503 9:30 []}, Group17{504 9:30 []}, Group18{505 9:30 []}, Group19{506 9:30 []}, Group20{507 9:30 []}], [Group21{501 9:45 []}, Group22{502 9:45 []}, Group23{503 9:45 []}, Group24{504 9:45 []}, Group25{505 9:45 []}, Group26{506 9:45 []}, Group27{507 9:45 []}]][5E:3:BBB]";
    	int normalGroupSize = 4;
		int group = 7;
    	LinkedList<String> roomNum=new LinkedList<String>();
		roomNum.add("501");
		roomNum.add("502");
		roomNum.add("503");
		roomNum.add("504");
		roomNum.add("505");
		roomNum.add("506");
		roomNum.add("507");

	
		Timetable chineseTimeTable=new Timetable("Chinese","101","1/2",540,15,4,28,7,roomNum);
		String actualOuputString = new Scheduler().schedule(chineseTimeTable, studentList, normalGroupSize, group, roomNum);
		
		assertEquals(expectedOuputString.equals(actualOuputString), true);
    }
}
